package com.niuke;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

/**
 * 29. 最小循环子数组
 * https://blog.csdn.net/m0_46181452/article/details/131489176
 */
public class NiukeMoni29 {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        String[] input = scanner.nextLine().split(" ");

        Map<String, Integer> counts = new HashMap<>();
        for (int i = 0; i < input.length; i++) {
            counts.put(input[i], counts.getOrDefault(input[i], 0) + 1);
        }

        if (counts.size() == 1) { // 数组都由同一个数字组成
            System.out.println(input[0]);
            return;
        }

        int minCount = Integer.MAX_VALUE;
        int maxCount = 0;
        int maxGcd = counts.get(input[0]);
        Set<Integer> countSet = new HashSet<>();
        for (Integer c : counts.values()) {
            maxGcd = gcd(maxGcd, c);
            minCount = Math.min(minCount, c);
            maxCount = Math.max(maxCount, c);
            countSet.add(c);
        }

        // 所有数字出现的个数的最大公约数是1，那么就无法分段循环，得到整个数组作为结果即可
        if (maxGcd == 1) {
            System.out.println(Arrays.toString(input));
            return;
        }

        // 对出现的次数做从大到小排序，最小循环子串的长度就是总长度除以当前次数，当出现符合条件的结果就可以break。
        List<Integer> countList = new ArrayList<>(countSet);
        countList.sort(new Comparator<Integer>() {
            @Override
            public int compare(Integer integer, Integer t1) {
                return t1 - integer;
            }
        });

        int resultLength = 0;
        for (int i = 0; i < countList.size(); i++) {
            int co = countList.get(i);
            if (input.length % co == 0 && countList.get(i) % minCount == 0){
                resultLength = input.length / co;
                String[] a = Arrays.copyOfRange(input, 0, resultLength);
                boolean isCan = true;
                for (int j = 1; j < co; j++) {
                    String[] b = Arrays.copyOfRange(input, resultLength * j, resultLength * (j + 1));
                    if (!Arrays.toString(a).equals(Arrays.toString(b))) {
                        isCan = false;
                        break;
                    }
                }
                if (isCan) {
                    break;
                } else {
                    resultLength = 0;
                }
            }
        }

        if (resultLength == 0) {
            System.out.println(Arrays.toString(input));
        } else {
            String[] result = Arrays.copyOfRange(input, 0, resultLength);
            System.out.println(Arrays.toString(result));
        }


    }

    public static int gcd(int a, int b){
        return a >= b ? (a % b == 0 ? b : gcd(b, a % b)) : gcd(b, a);
    }



}
